#include "PrecompiledHeaders.h"
#include "PlayManager.h"

/*
 * Grab state pointers
 */
void PlayManager::getStatePointers()
{
    menu = (MenuInGame *)((MenuState *)findByName("in_game_menu"));
    suPlayState = (SingleUserPlayState *)findByName("single_user_play");
}

/*
 * Clear all sessions
 */
void PlayManager::clearSessions()
{
    for(unsigned int i=0; i<sessions.size(); i++) {
        delete sessions[i];
    }
    sessions.clear();
}

/*
 * Inspect the session class to determine StateOfPlay
 */
void PlayManager::updateStateFromSession(GameSession *session)
{
    switch(session->getState())
    {
        case ssSUCCESSFUL:
            currentState = psSUCCESSFUL;
            return;
            
        case ssFAILED:
            currentState = psFAILED;
            return;
            
        case ssQUIT:
            currentState = psFINISHED;
            return;
            
        default:
            break;
    }
}

/*
 * Inspect the menu state to determine StateOfPlay
 */
void PlayManager::updateStateFromMenu()
{
    switch(menu->getState())
    {
        case lsQUIT:
            currentState = psFINISHED;
            return;
            
        case lsREPLAY_LEVEL:
            currentState = psREPLAY_LEVEL;
            menu->resetState();
            return;
            
        case lsNEXT_LEVEL:
            currentState = psNEXT_LEVEL;
            menu->resetState();
            return;
            
        case lsPLAY_REPLAY:
            currentState = psPLAY_REPLAY;
            menu->resetState();
            return;
            
        default:
            break;
    }
}
